<?php
namespace app\api_wp_v01\controller;

class Home extends ApiWechatProgram {
	
	/**
	 * 获取基础信息
	 */
	public function get_baseinfo() {
		
		return $this->disposeJson(0, '', array(
			'banner_list' => $this->get_banner(),
			'target_list' => $this->get_recycle_target(),
			'cargo_list' => $this->get_recycle_cargo(),
		));
		
	}
	
	/**
	 * 获取广告
	 */
	private function get_banner() {
		
		// 查询数据
		$banner_select = \app\common\model\BannerModel::where('is_del', 0)->where('is_disable', 0)->select();
		
		// 拼装数据结构
		$banner_list = array();
		foreach($banner_select as $BannerModel){
			$banner_list[] = \think\Config::get('application_domain') . $BannerModel->img_url;
		};
		
		// 返回结果
		return $banner_list;
	}
	
	/**
	 * 获取回收目标
	 */
	private function get_recycle_target() {
		
		// 查询数据
		$field = array(
			'name', 'image'
		);
		$target_select = \app\common\model\RecycleTargetModel::field($field)
			->where('is_del', 0)
			->where('is_disable', 0)
			->order('sort ASC')
			->select();
		
		// 拼装数据结构
		$target_list = array();
		foreach($target_select as $RecycleTargetModel){
			
			$target_list[] = array(
				'name' => $RecycleTargetModel->name,
				'image' => \think\Config::get('application_domain') . $RecycleTargetModel->image,
			);
		};
		
		// 返回结果
		return $target_list;
	}
	
	/**
	 * 获取回收货物
	 */
	private function get_recycle_cargo() {
		
		// 查询数据
		$field = array(
			'name', 'image'
		);
		$cargo_select = \app\common\model\RecycleCargoModel::field($field)
			->where('is_del', 0)
			->where('is_disable', 0)
			->order('sort ASC')
			->select();
		
		// 拼装数据结构
		$cargo_list = array();
		foreach($cargo_select as $RecycleCargoModel){
			
			$cargo_list[] = array(
				'name' => $RecycleCargoModel->name,
				'image' => \think\Config::get('application_domain') . $RecycleCargoModel->image,
			);
		};
		
		// 返回结果
		return $cargo_list;
	}
	
}